package test02;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: YKH
 * Date: 2022-05-13
 * Time: 19:19
 * author:Calu
 */
public class Calu {
    public static void main(String[] args) {
       new MyFrame();
    }
}

class MyFrame extends Frame {
    public MyFrame() {
        //setLayout(null);
        setBounds(100,200,500,400);
        setBackground(Color.BLACK);

        //创建输入框
        TextField textField = new TextField();
        add(textField);
        //设置替换编码
        textField.setEchoChar('*');
        //监听这个文本框中的事件
        MyActionListener myActionListener = new MyActionListener();
        textField.addActionListener(myActionListener);
       // pack();
        setVisible(true);
    }
}

//创建监听
class MyActionListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        TextField field = (TextField) e.getSource();//获得一些资源
        System.out.println(field.getText()); //获得输入框的文本
        field.setText("");

    }
}